/**   
 * @Title: ChaseRecordCommunicater.java 
 * @Package: com.esun.rabbit2.communicaters.chaserecord 
 * @Description: (追号记录通讯类) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-7-21 上午10:23:34  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.trackingrecord;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.TrackingRecordInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: ChaseRecordCommunicater
 * @Description: (追号记录通讯接口)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-7-21 上午10:23:34
 */
public class TrackingRecordCommunicater extends ServerCommunicater {

	private String msgServer;
	private String USERSESSION = UserInfo.getUserInfo().getUserSession();

	public void setMsgServer(String str) {
		this.msgServer = str;
	}

	public String getMsgServer() {
		return msgServer;
	}

	public boolean isGetTrackingRecord(String lotid, String pageno, String seltype) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(Config.PASER_MID, BussinessCode.MID_ZHUIHAO_JILU_LIEBIOA));
		list.add(mapItem(Config.PASER_CK, USERSESSION));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_PAGENO, pageno));
		list.add(mapItem(Key.KEY_PAGESIZE, Config.PAGE_SIZE));
		list.add(mapItem(Key.KEY_SELTYPE, seltype));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		EDebug.o(this, super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
		}
		return isSucceed;
	}

	public ArrayList<TrackingRecordInfo> updataTrackingRecordInfo() {
		ArrayList<TrackingRecordInfo> listTrackingRecordInfo = new ArrayList<TrackingRecordInfo>();
		ArrayList<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();
		list = super.getListResult();
		int listSize = list.size() ;
		Hashtable<String, String> htItem = new Hashtable<String, String>();
		for (int i = 0; i < listSize; i++) {
			htItem = list.get(i) ;
			TrackingRecordInfo newTrackingRecordInfo = new TrackingRecordInfo();
			newTrackingRecordInfo.setID(htItem.get(Key.KEY_ID));
			newTrackingRecordInfo.setLotID(htItem.get(Key.KEY_LOTTYPE));
			newTrackingRecordInfo.setAddDate(htItem.get(Key.KEY_ADDTIME));
			newTrackingRecordInfo.setAllMoney(htItem.get(Key.KEY_ALLMONEY));
			newTrackingRecordInfo.setTotalTrackingNum(htItem.get(Key.KEY_EXPECTNUM));
			newTrackingRecordInfo.setFinishTrackingNum(htItem.get(Key.KEY_FINISHNUM));
			newTrackingRecordInfo.setPlayTypeName(htItem.get(Key.KEY_PLAYTYPENAME));
			newTrackingRecordInfo.setState(htItem.get(Key.KEY_STATE));

			listTrackingRecordInfo.add(newTrackingRecordInfo);
		}
		return listTrackingRecordInfo;
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
